package com.millstein.tsinglog.controller;

import com.millstein.tsinglog.annotation.ResponseResult;
import com.millstein.tsinglog.model.pojo.Permission;
import com.millstein.tsinglog.service.PermissionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
@ResponseResult
@CrossOrigin
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取所有的权限信息
     * @return
     */
    @GetMapping("/getAllPermissions")
    @RequiresPermissions("role:assignPermission")
    public List<Permission> getAllPermissions() {
        return permissionService.getAllPermissions();
    }

    /**
     * 根据roleId查询权限
     * @param roleId
     * @return
     */
    @GetMapping("/getPermissionByRole")
    @RequiresPermissions("role:assignPermission")
    public List<Permission> getPermissionByRole(Long roleId) {
        return permissionService.getPermissionByRole(roleId, false);
    }

}
